<template>
  <div class="tab-control">
    <div v-for="(item, index) in titles" :key="index" class="tab-control-item" :class="{ active: acIndex == index }" @click="itemClick(index)">
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
import { ref } from "vue";
export default {
  props: {
    titles: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  setup(props, { emit }) {
    const acIndex = ref(0);

    const itemClick = (index) => {
      acIndex.value = index;
      emit("tabClick", index);
    };

    return {
      acIndex,
      itemClick,
    };
  },
};
</script>

<style lang="scss" scoped>
.tab-control {
  position: sticky;
  top: 46px;
  z-index: 9;
  display: flex;
  width: 100%;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 14px;
  background-color: #ffffff;
  .tab-control-item {
    flex: 1;
    span {
      padding: 6px;
    }
  }
  .active {
    color: var(--color-tint);
    span {
      border-bottom: 2px solid var(--color-tint);
    }
  }
}
</style>
